﻿namespace DesignModeConsole.创建型.抽象工厂模式.Sample2;

public interface Tax
{
    double Calculate();
}

public interface Bonus
{
    double Calculate();
}

/// <summary>
/// AbstractFactory类
/// </summary>
public abstract class AbstractFactory
{
    public static AbstractFactory GetInstance()
    {
        var factoryName = "ChineseFactory";

        AbstractFactory instance;

        if (factoryName == "ChineseFactory")
        {
            instance = new ChineseFactory();
        }
        else if (factoryName == "AmericanFactory")
        {
            instance = new AmericanFactory();
        }
        else
        {
            instance = null;
        }

        return instance;
    }

    public abstract Tax CreateTax();

    public abstract Bonus CreateBonus();
}

public class ChineseFactory : AbstractFactory
{
    public override Tax CreateTax()
    {
        return new ChineseTax();
    }

    public override Bonus CreateBonus()
    {
        return new ChineseBonus();
    }
}

public class AmericanFactory : AbstractFactory
{
    public override Tax CreateTax()
    {
        return new ChineseTax();
    }

    public override Bonus CreateBonus()
    {
        return new ChineseBonus();
    }
}